#ifndef RESULTMODEL_H
#define RESULTMODEL_H

#include <QAbstractTableModel>
#include <QVector>

class ResultModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit ResultModel(QObject *parent = nullptr);

    Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    Q_INVOKABLE void setHeader(QVariantList title){
        m_header.clear();
        m_header = title;
    }

    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    Q_INVOKABLE void setTableValue(QHash<int,QVariantList> data);
    Q_INVOKABLE void insertRowData(int index,QVariantList data);
    Q_INVOKABLE void appendRowData(QVariantList data);
    Q_INVOKABLE void modifyData(int row,int column,QVariant data);

    Q_INVOKABLE void refresh();
    Q_INVOKABLE void replaceModel(QHash<int,QVariantList>);


    bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;

    // Basic functionality:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    Qt::ItemFlags flags(const QModelIndex& index) const override;

    // Add data:
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
    bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;

    // Remove data:
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
    bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;

private:
    QVariantList m_header;
    QHash<int,QVariantList> hash;
};

#endif // RESULTMODEL_H
